/* ****************************************************************************
 * Author: 671643387
 * Date: 2016/5/10
 * ***************************************************************************/

var util = require('util');
var mysql = require('mysql');

var config = require('./config.js');

var dbConn = mysql.createConnection(config.GMMysql);
dbConn.connect(function(err){
    if (err) {
        console.log(util.format("%j\n", err));
    } else {
        dbConn.query("SELECT * FROM log;", function(err, rows, fields){
            if (err) {
                console.log(util.format("%j\n", err));
            } else {
                console.log("id,sid,name,ip,method,openid,uid,req,time,resp");
                rows.forEach(function(row){
                    console.log(
                        util.format("%d,%s,%s,%s,%s,%s,%s,%s,%s,%s",
                            +row['id'], row['sid'], row['name'],
                            row['ip'], row['method'], row['openid'],
                            row['uid'], row['req'], row['time'], row['response']
                        )
                    );
                });
            }
            dbConn.end();
        });
    }
});